package com.dadie.dorm.service.impl;




import com.dadie.dorm.dao.IHouseDao;
import com.dadie.dorm.dao.impl.HouseDaoImpl;
import com.dadie.dorm.pojo.House;
import com.dadie.dorm.pojo.query.HouseQuery;
import com.dadie.dorm.service.IHouseService;
import com.dadie.dorm.util.LayUITableResult;

import java.util.List;

public class HouseServiceImpl implements IHouseService {
    public IHouseDao houseDao=new HouseDaoImpl();
    @Override
    public LayUITableResult selectByPage(HouseQuery houseQuery) {
        List<House> list=houseDao.selectByPage(houseQuery);
        Integer totalCount=houseDao.selectTotalCount(houseQuery);
        return LayUITableResult.ok(totalCount,list);
    }

    @Override
    public boolean deleteById(int id) {
        int count=houseDao.deleteById(id);
        return count==1 ? true: false;
    }

    @Override
    public boolean add(House house) {
        int count=houseDao.add(house );
        return count==1 ? true: false;
    }



    @Override
    public boolean deleteAll(String[] ids) {
        // delete from house where id in();
        int count = 0;
        for (String id : ids) {
            count += houseDao.deleteById(Integer.parseInt(id));
        }
        return count == ids.length ? true : false;
    }

    @Override
    public boolean update(House house) {
        int count=houseDao.update(house);
        return count==1 ? true: false;
    }

    @Override
    public House selectById(int id) {
        return houseDao.selectById(id);

    }
}
